<template>
  <a-form-model
    ref="ruleForm"
    :model="form"
    :rules="rules"
    :label-col="{ span: 8 }"
    :wrapper-col="{ span: 16 }"
  >
    <a-form-model-item ref="mobile" label="手机号" prop="mobile">
      <!-- <a-input v-model="form.mobile" class="w-72" /> -->
      {{ form.mobile }}
    </a-form-model-item>

    <a-form-model-item label="状态">
      <a-radio-group v-model="form.enable">
        <a-radio :value="1"> 启用 </a-radio>
        <a-radio :value="0"> 禁用 </a-radio>
      </a-radio-group>
    </a-form-model-item>

    <a-form-model-item ref="fee_ratio" label="佣金比例" prop="fee_ratio">
      <a-input-number
        class="w-72"
        :step="0.001"
        :min="0"
        :max="max_fee"
        v-model="form.fee_ratio"
      />
    </a-form-model-item>
    <a-form-model-item ref="tip" label="单笔奖励" prop="tip">
      <a-input-number
        class="w-72"
        :step="1"
        :min="0"
        :max="max_tip"
        v-model="form.tip"
      />
    </a-form-model-item>
  </a-form-model>
</template>
<script>
export default {
  data() {
    return {
      id: null,
      max_fee: 0,
      max_tip: 0,
      form: {
        fee_ratio: 0,
        tip: 0,
        mobile: '',
        enable: 0,
      },
      rules: {
        // mobile: [
        //   {
        //     required: true,
        //     message: '请输入',
        //     trigger: 'blur',
        //   },
        // ],
        fee_ratio: [
          {
            required: true,
            message: '请输入',
            trigger: 'blur',
          },
        ],
        tip: [
          {
            required: true,
            message: '请输入',
            trigger: 'blur',
          },
        ],
      },
    }
  },
  methods: {
    init(row) {
      this.id = row.id
      this.form = {
        tip: row.tip,
        fee_ratio: row.fee_ratio,
        mobile: row.mobile,
        enable: row.enable ? 1 : 0,
      }
      const user = this.$store.state.account.user
      // console.log(user)
      this.max_fee = parseFloat(user.fee_ratio)
      this.max_tip = parseFloat(user.tip)
    },
    onSubmit(ok) {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          this.axios.put(`/g/members/${this.id}`, this.form).then((res) => {
            if (res.data.code === 1) {
              ok()
            } else {
              this.$message.error(res.data.msg)
            }
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
  },
}
</script>
